package com.sgb.kjwl.view.ui.activity.ShoppingCar;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sgb.goods.utils.Constants;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityOrderedSuccessfullyBinding;
import com.sgb.kjwl.view.ui.activity.MainActivity;

/**
 * 描述： 商品下单成功
 *
 * @author qiangHeNooo
 * <p>
 * 时间： 2021.04.22
 */
public class OrderedSuccessfullyActivity extends AppActivity {

    private ActivityOrderedSuccessfullyBinding binding;
    /***
     * 默认推荐项
     */
    private final String mChannelName = "商品";

    public static final String MESSAGE_KEY = "message_key";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected boolean statusBarDark() {
        return false;
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_ordered_successfully);
        binding.include.titleView.setText("下单成功");
        binding.include.ivBack.setOnClickListener(this);
        binding.tvBack.setOnClickListener(this);
        binding.tvView.setOnClickListener(this);
    }

    @Override
    protected void init() {
        Intent intent = getIntent();
        if (intent != null) {
            String extra = intent.getStringExtra(MESSAGE_KEY);
            binding.goodsMessage.setText(extra);
        }
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onMultiClick(View v) {
        switch (v.getId()) {
            case R.id.tv_back:
            case R.id.iv_back:
                Intent intent = new Intent(OrderedSuccessfullyActivity.this, MainActivity.class);
                intent.putExtra("checkName", mChannelName);
                MainActivity.start(this, intent);
                finish();
                break;
            case R.id.tv_view:
                ARouter.getInstance().build(Constants.ARouter.AR_PURCHASE_ORDER_LIST).navigation();
                finish();
                break;
            default:
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Intent intent = new Intent(OrderedSuccessfullyActivity.this, MainActivity.class);
            intent.putExtra("checkName", mChannelName);
            MainActivity.start(this, intent);
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}